from flask import Flask
from config import Config
from apps.util import init_db
from apps import db

# 导入蓝图
from apps.task.views import task_bp
from apps.account.view import account_bp
from apps.admin.view import admin_bp
from apps.course.view import course_bp
from apps.major.view import major_bp
from apps.teacher.view import teacher_bp
from apps.student.view import student_bp
from apps.score.view import score_bp

def create_app():
    app = Flask(__name__)
    app.config.from_object(Config)
    app.url_map.strict_slashes = False

    # 初始化扩展
    db.init_app(app)

    # 注册蓝图
    app.register_blueprint(task_bp)
    app.register_blueprint(account_bp)
    app.register_blueprint(teacher_bp)
    app.register_blueprint(major_bp)
    app.register_blueprint(student_bp)
    app.register_blueprint(admin_bp)
    app.register_blueprint(course_bp)
    app.register_blueprint(score_bp)

    # 初始化数据库
    init_db(app)

    return app

if __name__ == '__main__':
    app = create_app()
    app.run(host='0.0.0.0', port=5000, debug=True)